
<!DOCTYPE HTML>
<html lang="en" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Routes · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="cli.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    Topics
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="routes.html">
            
                <a href="routes.html">
            
                    
                    Routes
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="cli.html">
            
                <a href="cli.html">
            
                    
                    CLI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="validation.html">
            
                <a href="validation.html">
            
                    
                    Validation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="openapi.html">
            
                <a href="openapi.html">
            
                    
                    Open API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="metrics.html">
            
                <a href="metrics.html">
            
                    
                    Metrics
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Routes</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="routes">Routes</h1>
<h2 id="definitions">Definitions</h2>
<p>Defining routes and be as easy as defining such functions:</p>
<pre><code class="lang-go"><span class="hljs-keyword">func</span> handler(request Request) (Response, error) {
  <span class="hljs-comment">// do stuff</span>
  <span class="hljs-comment">// return data</span>
  <span class="hljs-comment">// or error if anything wrong happened</span>
}
</code></pre>
<p>However we can do a lot more with Nirvana framework!</p>
<h3 id="declarative-approach-to-routes-definition">Declarative approach to routes definition</h3>
<p>In Nirvana, routes definitions <em>are</em> documentations, i.e. you will only need to follow the <em>DRY</em> rule, define your routes (w.r.t specific formats) and then we&apos;ll try to cover these for you:</p>
<ul>
<li>basic test-case generation</li>
<li>OpenAPI docs generation</li>
<li>parameter checking (against function signatures)</li>
<li>etc.</li>
</ul>
<h3 id="definitiondescriptor-struct"><code>definition.Descriptor</code> struct</h3>
<p>This is the core data structure that you&apos;ll use, and a typical example looks like this:</p>
<pre><code class="lang-go">definition.Descriptor{
  Path:        <span class="hljs-string">&quot;/api&quot;</span>,
  Description: <span class="hljs-string">&quot;here goes your api description&quot;</span>,
  Produces:    []<span class="hljs-keyword">string</span>{<span class="hljs-string">&quot;text/plain&quot;</span>},
  Definitions: []definition.Definition{
    {
      Method: definition.Get,
      Function: <span class="hljs-keyword">func</span>(ctx context.Context) (<span class="hljs-keyword">string</span>, error) {
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;Hello World!&quot;</span>, <span class="hljs-literal">nil</span>
      },
      Parameters: []definition.Parameter{},
      Results: []definition.Result{
        {
          Type: definition.Data,
        },
        {
          Type: definition.Error,
        },
      },
    },
  },
}
</code></pre>
<p>TODO: add more</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="cli.html" class="navigation navigation-next navigation-unique" aria-label="Next page: CLI">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Routes","level":"1.2.1","depth":2,"next":{"title":"CLI","level":"1.2.2","depth":2,"path":"topics/cli.md","ref":"topics/cli.md","articles":[]},"previous":{"title":"Topics","level":"1.2","depth":1,"ref":"","articles":[{"title":"Routes","level":"1.2.1","depth":2,"path":"topics/routes.md","ref":"topics/routes.md","articles":[]},{"title":"CLI","level":"1.2.2","depth":2,"path":"topics/cli.md","ref":"topics/cli.md","articles":[]},{"title":"Validation","level":"1.2.3","depth":2,"path":"topics/validation.md","ref":"topics/validation.md","articles":[]},{"title":"Open API","level":"1.2.4","depth":2,"path":"topics/openapi.md","ref":"topics/openapi.md","articles":[]},{"title":"Metrics","level":"1.2.5","depth":2,"path":"topics/metrics.md","ref":"topics/metrics.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"en","gitbook":"*"},"file":{"path":"topics/routes.md","mtime":"2019-08-06T09:48:58.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-20T10:33:16.586Z"},"basePath":"..","book":{"language":"en"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

